<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link href="<s:url value="/css/style.css"/>" rel="stylesheet"
			type="text/css" />
		<link href="<s:url value="/css/jquery.css"/>" rel="stylesheet"
			type="text/css" />
		<script type="text/javascript"
			src="<s:url value="/js/jquery-1.3.2.min.js"/>"></script>
		<script type='text/javascript'
			src="<s:url value="/js/autocomplete/jquery.bgiframe.min.js"/>"></script>
		<script type='text/javascript'
			src="<s:url value="/js/autocomplete/jquery.ajaxQueue.js"/>"></script>
		<script type='text/javascript'
			src="<s:url value="/js/autocomplete/thickbox-compressed.js"/>"></script>
		<script type='text/javascript'
			src="<s:url value="/js/autocomplete/jquery.autocomplete.js"/>"></script>
		<script type="text/javascript" src="<s:url value="/js/common.js"/>"></script>
		<link rel="stylesheet" type="text/css"
			href="<s:url value="/js/autocomplete/jquery.autocomplete.css"/>" />
		<link rel="stylesheet" type="text/css"
			href="<s:url value="/js/autocomplete/thickbox.css"/>" />
		<script type="text/javascript"
			src="<s:url value="/js/jquery.blockUI.js"/>"></script>
		<link href="<s:url value="/css/jquery.css"/>" rel="stylesheet"
			type="text/css" />
		<script type='text/javascript' src="<s:url value="/js/tableSel2.js"/>"></script>
		<script type="text/javascript" src="<s:url value="/js/jquery-ui.js"/>"></script>
		<script type="text/javascript"
			src="<s:url value="/js/jquery.tablesorter.min.js"/>"></script>
		<script type="text/javascript">
	    $(document).ready(function(){
	    	 
             $("#curTime").change(function(){
                  var  curtime=$("#curTime option:selected").val();
                  $("#classentityid").val("");
                  $("#curFocus").val("");
                  $("#curTopic").val("");
                  $('#curLeadsClasses').find("tr:gt(0)").remove();
                  $('#classtable').find("tr").remove();
                  if (!curtime){
                     return ;
                  }
                  var curdate=$('#curDate').attr('value');
                  var url = "<s:url value="/academic/ClassCheckin/selectCheckinTime.action"/>";
                  var params = {
                      curdate:curdate,
		              curtime:curtime 
                  };
                  jQuery.post(url, params, callbackFun);
            });
            $("#selstudent").autocomplete("<s:url value="/customer/Leads/autoCompleteAjax.action"/>", {
              width: 300,
              minChars:2, //几个字
              mastMatch:true,
              selectFirst: false,
              max:  20,
           	  formatItem: function(row, i, max) {
           	      //alert(row);
           	      var d=eval("("+row+")");
           	      //alert(d);
			      return  d.name+" "+ d.card +" " + d.tel;
	         },
		     formatMatch: function(row, i, max) {
		         var d=eval("("+row+")");
 			     return  d.name+" "+ d.card +" " + d.tel;
		     },
		     formatResult: function(row) {
		        // alert(row);
		         var d=eval("("+row+")");
			     return d.name+" "+ d.card ;
     	      }
           });
           $("#selstudent").result(function(event, data, formatted) {
           	      var d=eval("("+data+")");
		          $("#selstudentid").val(d.id);
           });
           $('#selClassDate').datepicker( {dateFormat :'yy-mm-dd'});
    });
   //选到某节课
    function doSelectCheckinEntityById(Eid){
         $.blockUI({ css: { 
                    border: 'none', 
                    padding: '15px', 
                    backgroundColor: '#000', 
                    '-webkit-border-radius': '10px', 
                    '-moz-border-radius': '10px', 
                    opacity: .5, 
                    color: '#fff' 
          }});  
          if ( $('#classentityid').val()){
             $("#span"+$('#classentityid').val()).css("font-weight","normal");
          }
          $("#span"+Eid).css("font-weight","bolder");
          $('#classentityid').val(Eid);
          var url = "<s:url value="/academic/ClassCheckin/selectCheckinEntity.action"/>";
          var params = {
               entityid:Eid 
          };
          jQuery.post(url, params, callbackSelectClassFun);
    };
    //新加一个学生
    function doAddStudent(confirm){
          var  classentityid=$('#classentityid').val();
          var  selstudentid=$("#selstudentid").val();
          if (!classentityid||!selstudentid){
             alert("please select one class and one student");
             return;
          }
          $.blockUI({ css: { 
                    border: 'none', 
                    padding: '15px', 
                    backgroundColor: '#000', 
                    '-webkit-border-radius': '10px', 
                    '-moz-border-radius': '10px', 
                    opacity: .5, 
                    color: '#fff' 
        } });
         var url = "<s:url value="/academic/ClassCheckin/doAddStudent.action"/>";
         var params = {
             classentityid:classentityid,
		     selstudentid:selstudentid,
		     confirm:confirm
         };
         jQuery.post(url, params, callbackSelectClassFun);
    };
    
    function doCheckin(){
      	  var  classentityid=$('#classentityid').val();
    	  if (!classentityid){
             alert("please select one class ");
             return ;
          }
          if(!confirm('are you sure checkin this class ?')){
		         return;
	      }
	      var ids = getSelectionIds('a');
	      if(ids.length<1){
		      if(!confirm('are you sure nobody checkin at this class ?')){
		         return;
	          }
	      }
	      $.blockUI({ css: { 
                    border: 'none', 
                    padding: '15px', 
                    backgroundColor: '#000', 
                    '-webkit-border-radius': '10px', 
                    '-moz-border-radius': '10px', 
                    opacity: .5, 
                    color: '#fff' 
                } });  
	      $('#ids').val(ids);
	      var url = "<s:url value="/academic/ClassCheckin/doCheckin.action"/>";
          var params = {
               classentityid:classentityid,
               leadsclassids:$('#ids').val()
          };
          jQuery.post(url, params, callbackSelectClassFun);
    };
    function callbackFun(data)
         {
              setTimeout($.unblockUI, 500); 
              var cls=0;   
              var color="#ADFF2F"; //green
              $(data).find('response>entity').each(function(){
                  var d=eval("("+$(this).text()+")"); 
                  if (cls%8==0){
                     $('#classtable').append("<tr></tr>");
                  }
                  if (d.ctimes==0){
                     color="#ADFF2F";//green
                  }else{
                     color="#EE4000";//red
                  };
                  $("#classtable").find("tr:last").append("<td bgcolor=\""+color
                  +"\"  onclick=\"javascript:doSelectCheckinEntityById('"
                  +d.classid+"');\" ><span id=\"span"+d.classid+"\"  style=\"cursor:pointer\" >"
                       +d.tname+"@"+d.cname+"</span></td>");
                  cls++;     
       　　　　　　 });
 　　　      };
     function callbackSelectClassFun(data)
         {
              setTimeout($.unblockUI, 500); 
              var nreturn=false;
              $(data).find('response').each(function(){　　　　　　　　　　　　　　　　　　
　 　　　　　　　　  var type= $(this).children("type").text() ;
                  if  (type==="warn"){
                       var msg=$(this).children("info").text();
                       $("#info").val(msg);
                        var confirmmsg= $(this).children("confirm").text() ;
                        if(confirm(msg)){
		                   doAddStudent(confirmmsg);
		                   return;
	                    }else{ 
	                        nreturn=true;
	                        return;
 	                    }
                  }else if  (type==="error"){
                      $("#info").val($(this).children("info").text());
                      alert($(this).children("info").text());
                      nreturn=true;
                      return ;
                  }
  　　　　　　　 });
              if (nreturn){
                 return;
              }
              $('#curLeadsClasses').find("tr:gt(0)").remove();
              $(data).find('response>class').each(function(){
                  var d=eval("("+$(this).text()+")"); 
                  $("#classentityid").val(d.id);
                  $("#curFocus").val(d.focus);
                  $("#curTopic").val(d.topic);
              });
              $(data).find('response>entity').each(function(){
	            var d=eval("("+$(this).text()+")"); 
	            var checkstatus="";
	            if (d.status=="Booking"){
	                 checkstatus= " checked=\"checked\" ";
	            }else  if (d.status==="Waiting"){
	                 checkstatus="";
	            }else if (d.status==="Checkin"){
	                 checkstatus= " checked=\"checked\" ";
	                // checkstatus= "disabled=\"disabled\"";
	            };
	            $('#curLeadsClasses').append("<tr><td class=\"tablecolour2\">"
	              +"<input type=\"checkbox\" "+ checkstatus + " name='a' value=\""+d.id+"\"/></td>"
	              +"<td class=\"tablecolour2\">"+d.sname+"</td>"
	              +"<td class=\"tablecolour2\">"+d.card+"</td>"
	              +"<td class=\"tablecolour2\">"+d.tel+"</td>"
	              +"<td class=\"tablecolour2\">"+d.btime+"</td>"
	              +"<td class=\"tablecolour2\">"+d.ctime+"</td>"
	              +"<td class=\"tablecolour2\">"+d.status+"</td></tr>");
      　　　  　 });
           //$("#curLeadsClasses").tablesorter();
 　　　      };
        function doSubmit(){
		    $('#listForm').submit();
		}
   </script>
	</head>
	<body>
		<s:include value="/common/up.jsp"></s:include>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td class="box">
					<s:form action="ClassCheckin/beforeCheckin" name="listForm" id="listForm"
						namespace="/academic">
						<table width="100%" border="0" cellpadding="0" cellspacing="0"
							class="searchbg">
							<tr>
								<td colspan="3">
								<s:if test="isManager()">
							 	    <s:textfield id="selClassDate" name="classDate"
											cssClass="input2" size="10" />
								</s:if>
								<s:else>
									<s:date name="classDate" format="E yy-MM-dd" />
								</s:else>
									&nbsp;
								<input id="curDate" type="hidden"
										value="<s:date  name="classDate" format="yyyy-MM-dd"/> ">
									Course Time
									<s:select id="curTime" name="classTime" headerKey=""
										headerValue="---------select---------"
										list="checkMessageMap" listKey="key" listValue="value" />
									<img onclick="javascript:doSubmit();" 
										src="<s:url value="/img/right/Refresh.gif"/>" border="0"
										align="absmiddle" />
								</td>
							</tr>
						</table>
						<table>
							<tr>
								<td>
									<s:hidden name="classentityid" id="classentityid" />
									Focus:
									<input id="curFocus" type="text" readonly="readonly" style="border-color:black; border-bottom: 2;border-left: 0;border-right: 0;border-top:0"/>
								</td>
								<td>
									Topic:
									<input id="curTopic" type="text" readonly="readonly" style="border-color:black; border-bottom: 2;border-left: 0;border-right: 0;border-top:0" />
								</td>
							</tr>
						</table>
						<table>
							<tr>
								<td>
									<table id="classtable">
									</table>
								</td>
							</tr>
						</table>
						<table>
							<tr>
								<td>
									<img src="<s:url value="/img/right/checkin.gif"/>"
										onclick="javascript:doCheckin();" border="0" align="absmiddle" />
								</td>
							</tr>
						</table>
						<table id="curLeadsClasses" width="100%" border="0"
							cellpadding="1" cellspacing="1" class="box2 ">
							<thead>
							<tr>
								<th class="tablecolour1">
								<input type="checkbox" name="all" onclick="checkAll('a',this)" checked />
									<s:hidden name="ids" id="ids" />
								</th>
								<th class="tablecolour1">
									Name
								</th>
								<th class="tablecolour1">
									EliteCards
								</th>
								<th class="tablecolour1">
									Telephone
								</th>
								<th class="tablecolour1">
									Booking Time
								</th>
								<th class="tablecolour1">
									Cancel Time
								</th>
								<th class="tablecolour1">
									Status
								</th>
							</tr>
							</thead>
							<tbody>
							<s:iterator value="leadsClassEntityList" status="status">
								<tr title="entity">
									<td class="tablecolour2">
										<input type="checkbox" name="a"
											value="<s:property value="id" />" />
									</td>
									<td class="tablecolour2">

									</td>
									<td class="tablecolour2">

									</td>
									<td class="tablecolour2">

									</td>
									<td class="tablecolour2">

									</td>
									<td class="tablecolour2">

									</td>
									<td class="tablecolour2">

									</td>
								</tr>
							</s:iterator>
							</tbody>
						</table>
					</s:form>
				</td>
			</tr>
		</table>
		<s:include value="/common/down.jsp"></s:include>
	</body>
</html>
